5 REM "Copy Left by B Mathias Johansson. (bmjbmj@telia.com)"
10 REM "RN-XV based WWW server"
15 reqTimeOut=3001:REM "Time out for req. header in ms"
16 DIM VARS$(2,10)
20 OPEN "COM3:115200, 1024" AS #1":REM "Open UEXT. Set TO your port""
30 GOSUB 1000:REM "Init RV-XV"
40 GOSUB 2000:REM "Join network"
100 REM "Main loop"
110 DO
120 PRINT #1,"exit":REM "Exit if we haven't already"
130 PAUSE 500
140 GOSUB 3000
160 timeout=0:reqtyp$="":err=0:REM"clear vars for gosubs"
170 GOSUB 7000:REM "Pars header"
180 PRINT"Err:";:PRINT timeout;:PRINT" ";:PRINT reqtype$;:PRINT err
190 IF timeout=1 THEN GOTO 240:REM "Close and reset"
200 IF err>0 THEN
205 page$="404.htm":REM "Send page not found"
210 GOSUB 6000
220 ELSE
225 page$="index.htm":REM "Send page"
230 GOSUB 6000
235 ENDIF
240 REM "Enter comand mode and close connection to client"
250 PAUSE 500
260 PRINT #1,"$$$";
265 PAUSE 500
270 PRINT #1,"close"
280 PAUSE 1000
290 PRINT #1,"exit"
300 PAUSE 500
310 GOSUB 3000
320 PRINT "Conetion closed"
998 LOOP
999 END
1000 REM "Init RV-XV to known state"
1005 REM "Exit comand mode if we haven't"
1010 PRINT #1,""
1020 PRINT #1,"exit"
1030 PAUSE 500
1040 REM "Enter comand mode"
1050 PRINT #1,"$$$";
1060 PAUSE 500
1065 in$=INPUT$(200,#1)
1066 PRINT in$
1070 REM "Reboote device into known state
1080 PRINT #1,"reboot"
1090 PAUSE 3000
1100 in$=INPUT$(200,#1)
1110 PRINT in$
1999 RETURN
2000 REM "Join the PREPROGRAMED network. Do not forget to configure the RV-XV!"
2004 REM "Enter comand mode"
2005 PAUSE 500
2010 PRINT #1,"$$$";
2020 PAUSE 500
2030 PRINT #1,"set comm remote 0":REM "No auto msg."
2031 PAUSE 500
2032 PRINT #1,"set comm open 0"
2033 PAUSE 500
2034 PRINT #1,"set comm close 0"
2035 PAUSE 500
2036 PRINT #1,"set comm idle 2":REM "Timeout link in 2s"
2040 PAUSE 500
2050 PRINT #1,"join":REM "Try to join"
2055 PAUSE 3000
2060 in$=INPUT$(255,#1)
2065 PRINT in$
2100 in$=INPUT$(255,#1)
2110 PRINT in$
2999 RETURN
3000 REM "Flush RX"
3005 REM "UGLY!!!! FIX THIS!!!!"
3006 REM PRINT "Debug av flush"
3010 in$=INPUT$(255,#1)
3015 REM PRINT in$;
3020 in$=INPUT$(255,#1)
3025 REM PRINT in$;
3030 in$=INPUT$(255,#1)
3035 REM PRINT in$;
3040 in$=INPUT$(255,#1)
3045 REM PRINT in$
3050 REM PRINT "end debug av flush"
3999 RETURN
4000 REM "Pars header for POST"
4999 RETURN
5000 REM "Set javascript variabels"
5999 RETURN
6000 REM "Send HTML"
6010 PRINT "Serving a page"
6020 OPEN page$ FOR input AS #2
6030 DO WHILE NOT EOF(#2)
6040 LINE INPUT #2,fl$
6045 IF reqtype$="POST" AND INSTR(fl$,"var pin") THEN GOSUB 9000
6050 PRINT #1,fl$
6060 PAUSE 1:REM "This value needs to be set higher on a slow network"
6070 LOOP
6080 CLOSE #2
6090 PRINT "Done transmiting page"
6999 RETURN
7000 REM "Pars header"
7010 PRINT "Waiting for client"
7020 in$=INPUT$(1,#1)
7030 IF in$="" GOTO 7020:REM "Wait for client"
7040 PRINT "Client called parsing header"
7050 TIMER=0
7060 DO WHILE TIMER <reqTimeOut
7070 t$=INPUT$(1,#1)
7080 IF t$<>CHR$(13) THEN
7090 in$=in$+t$:REM "Build one line"
7100 ELSE
7110 REM prinT in$;
7112 IF reqtype$="POST" THEN
7113 IF INSTR(in$,"Content-Length") THEN
7114 GOSUB 8000
7115 RETURN
7118 PRINT "hej"
7119 ENDIF:ENDIF
7120 IF INSTR(in$,"GET") THEN
7130 reqtype$="GET":REM "We have a GET req. and..."
7140 IF LEN(in$)>6 THEN
7150 IF MID$(in$,6,1)<>" " THEN
7160 err=404:REM "...if it's not for '/' page we dont have it!"
7165 RETURN
7170 ENDIF
7180 ENDIF
7185 RETURN:REM "No more parsing needed for GET"
7190 ENDIF
7200 IF INSTR(in$,"POST") THEN
7210 reqtype$="POST":REM "We have a POST req. and..."
7220 IF LEN(in$)>7 THEN
7230 IF MID$(in$,7,1)<>" " THEN
7240 err=404:REM "..if it's not for '/' page we dont have it!"
7250 RETURN
7260 ENDIF
7270 ENDIF
7280 ENDIF
7285 in$=""
7290 ENDIF
7900 LOOP
7910 timeout=1:REM "connection broke"
7999 RETURN
8000 REM "Pars POST vars"
8001 PRINT "Parsing POST vars"
8006 contLen=VAL(MID$(in$,18,LEN(in$)-17)):REM "Get the number from Header"
8014 in$=""
8015 REM "The timer is set in calling routin"
8020 DO WHILE TIMER < reqTimeOut
8030 t$=INPUT$(1,#1)
8040 in$=in$+t$
8049 REM "The rest of the data is the vars"
8050 IF LEN(in$)=contLen+3 THEN
8060 varLine$=RIGHT$(in$,contLen)
8065 REM "Split line into name/value pairs and stor in matrix VARS$"
8066 PRINT varLine$
8067 x=0
8068 y=0
8070 FOR i=1 TO contLen
8075 t$=MID$(varLine$,i,1)
8080 IF t$="=" THEN
8081 REM "Store var name"
8090 VARS$(x,y)=temp$
8095 PRINT temp$;
8100 temp$=""
8110 x=x+1
8130 ELSEIF t$="&" THEN
8131 REM "Store var value"
8140 VARS$(X,Y)=temp$
8145 PRINT temp$
8150 temp$=""
8155 x=0
8160 y=y+1
8170 ELSE
8171 REM "Just get next char"
8180 temp$=temp$+t$
8185 ENDIF
8190 REM "Error check"
8200 IF x>1 OR y>9 THEN
8210 err=1
8220 RETURN
8230 ENDIF
8300 NEXT i
8310 VARS$(X,Y)=temp$:REM"Store the rest as last value"
8320 PRINT temp$
8700 RETURN
8800 ENDIF
8900 LOOP
8910 timeout=1:REM "Connection broke"
8999 RETURN
9000 REM "This i the place to set the"
9010 REM "var pinx in the javascript to the"
9020 REM "right value"
9030 REM "This is a demo and only echo back the"
9040 REM "Post data"
9060 i=INSTR(fl$,"=")
9070 pinNo=VAL(MID$(fl$,8,i-8)): REM "extract pin no"
9075 REM "Inject the line 'var pinX=varX;' X=the pinNo"
9080 fl$="var pin"+STR$(pinNo)+"="+VARS$(1,pinNo-1)+";"
9090 PRINT "Injecting line:"
9100 PRINT fl$
9999 RETURN
